package com.sbillings.messenger.hub;

/**
 * MessageType (Info, Warning, Error, etc.).
 * Also provides name and int ID for each type, and provides a function (static method) for mapping an int ID
 * to the corresponding enum value.
 * @author steve.billings
 *
 */
public enum MessageType {
	UNDEFINED(0, "Undefined"), // getType() returns this if the given type ID is invalid 
	INFO(1, "Info"), // some news; nothing's wrong
	WARNING(2, "Warning"), // something doesn't seem quite right
	ERROR(3, "Error"), // there is definitely a problem
	INTERNALERROR(4, "Internal Error"), // an error generated from within the messenger hub software
	HEARTBEAT(5, "Heartbeat"); // an "I'm still alive" message (usually periodic)

	private int value;
	private String name;

	private MessageType(int value, String name) {
		this.value = value;
		this.name = name;
	}
	
	/**
	 * Function for mapping a message type ID to the enum value.
	 * @param value
	 * @return
	 */
	public static MessageType getType(int value) {
		if (value == MessageType.HEARTBEAT.getValue()) {
			return MessageType.HEARTBEAT;
		} else if (value == MessageType.INFO.getValue()) {
			return MessageType.INFO;
		} else if (value == MessageType.WARNING.getValue()) {
			return MessageType.WARNING;
		} else if (value == MessageType.ERROR.getValue()) {
			return MessageType.ERROR;
		} else if (value == MessageType.INTERNALERROR.getValue()) {
			return MessageType.INTERNALERROR;
		}
		return MessageType.UNDEFINED;
	}


	public int getValue() {
		return value;
	}

	public String getName() {
		return name;
	}

	
}
